package annotationtest.basicannotation;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {
	@SuppressWarnings("deprecation")
	public static void main(String[] args) {
		Person person = new Person("小明", 18);
		person.travelsByCarriage();

		suppressWarningTest();
		safeVarargsTest(
				Arrays.asList("Hello"),
				Arrays.asList("World"));

	}

	public static void suppressWarningTest() {
		@SuppressWarnings({ "unused", "resource" })
		Scanner s = new Scanner(System.in);
	}

	/**
	 * 类型安全:通过varargs参数args可能造成的堆污染
	 * @param listStrArray 需要传入的list对象，类型为String
	 * */
	@SafeVarargs
	public static void safeVarargsTest(List<String>... listStrArray) {
		//Java语言不允许创建泛型数组，因此listArray只能被当成List[]处理
		//此时相当于把List<String>赋给了List，已经发生了“堆污染”
		@SuppressWarnings("rawtypes")
		List[] listArray = listStrArray; 
		
		List<Integer> myList = new ArrayList<Integer>();
		myList.add(12);
		listArray[0] = myList;
		String string = listStrArray[0].get(0);
		System.out.println(string);
	}
}